package thread.threaddemo;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/10/16:34
 * @Description:yield让出执行权
 */
public class ThreadDemoYield {
    public static void main(String[] args) {
        Thread thread=new Thread(()->{
            Thread  cThread=Thread.currentThread();
            for (int i = 0; i < 100; i++) {
               Thread.yield();
                System.out.println("执行的线程为："+cThread.getName());
            }
        },"线程1");
        thread.start();

        Thread thread1=new Thread(()->{
            Thread  cThread=Thread.currentThread();
            for (int i = 0; i < 100; i++) {
                System.out.println("执行的线程为："+cThread.getName());
            }
        },"线程2");
        thread1.start();
    }
}
